<?php

class BaseController{
	public $view;
	protected $_request = null;
	static $instance = null;
	protected $_urlparams = null;
	function __construct(){
		require_once(PF_DIR.'/model/BaseView.php');
		$this->view = new BaseView();
		$this->frontcontroller = FrontController::getInstance();
		$this->_urlparams = $this->frontcontroller->_params;
	}
	
	public static function getInstance(){
		if (!self::$instance instanceof self) {
			self::$instance = new self();
        }
        return self::$instance;
	}
	public function getRequest(){
		$this->_request = self::getInstance();
        return $this->_request;
    }
    
    public function getParam($paramName){
    	return isset($this->_urlparams[$paramName]) ? $this->_urlparams[$paramName] : null;
    }
	
    public function getPost($paramName){
    	return isset($_POST[$paramName]) ? $_POST[$paramName] : null;
    }
    
    public function getModule(){
    	return $this->frontcontroller->module;
    }
    
    public function checkLogin(){
    	if($this->getModule() == 'admin'){
    		if(!isset($_SESSION)) session_start();
    		if(!isset($_SESSION['admin'])){
    			$this->_redirect(ROOT_URL.'/admin/login');
    		}	
    	}else{
    		if(!isset($_SESSION['user'])){
    			$this->_redirect(ROOT_URL);
    		}
    	}
    }
	function _redirect($url){
		header("Location:$url");
		exit();
	}
	function __destruct(){
		
	}
}

?>